From 48b9ed57f7977f40b68c9a8686d41f29f98c2e9f Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Fri, 19 Apr 2024 21:22:47 -0700
Subject: feat(badges): admin shadow hide

---
 src/routes/user/[user]/badges/+page.svelte | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

(limited to 'src/routes/user/[user]/badges/+page.svelte')

diff --git a/src/routes/user/[user]/badges/+page.svelte b/src/routes/user/[user]/badges/+page.svelte
index 817173bc..e3e44339 100644
--- a/src/routes/user/[user]/badges/+page.svelte
+++ b/src/routes/user/[user]/badges/+page.svelte
@@ -81,6 +81,13 @@
 		badges: AWCBadge[];
 	}
 
+	const getBadges = () => (badgesPromise = fetch(root(`/api/badges?id=${badger.id}`)));
+
+	const setShadowHide = () =>
+		fetch(`/api/badges?shadowHide=${badger.id}`, {
+			method: 'PUT'
+		}).then(getBadges);
+
 	onMount(async () => {
 		// socket.on('badges', (message) => (badges = message));
 
@@ -525,7 +532,7 @@
 
 							{#if authorised}
 								<div class="card">
-									<button>Shadow Hide Badges</button>
+									<button on:click={setShadowHide}>Shadow Hide Badges</button>
 								</div>
 
 								<p />
@@ -587,6 +594,11 @@
 									<!-- <!-- <span style="margin: 0 0.625rem;">•</span> -->
 									<!-- <button on:click={() => exportBadges(groupedBadges)}>Export Badges</button> -->
 
+									{#if ungroupedBadges.filter((badge) => badge.shadow_hidden).length > 0}
+										<span style="margin: 0 0.625rem;">•</span>
+										<button on:click={setShadowHide}>Un-shadow Hide Badges</button>
+									{/if}
+
 									{#if editMode && isOwner}
 										{@const groups = groupedBadges
 											.map((group) => group[0])
@@ -795,7 +807,9 @@
 															source={cdn(thumbnail(badge.image))}
 															alternative={badge.description}
 															fallback={thumbnail(badge.image)}
-															style={badge.hidden ? 'filter: grayscale(100%); opacity: 50%;' : ''}
+															style={badge.hidden || badge.shadow_hidden
+																? 'filter: grayscale(100%); opacity: 50%;'
+																: ''}
 														/>
 													</a>
 												</Tooltip>
@@ -807,7 +821,9 @@
 													alternative={badge.description}
 													fallback={thumbnail(badge.image)}
 													hideOnError={preferences.hide_missing_badges}
-													style={badge.hidden ? 'filter: grayscale(100%); opacity: 50%;' : ''}
+													style={badge.hidden || badge.shadow_hidden
+														? 'filter: grayscale(100%); opacity: 50%;'
+														: ''}
 												/>
 											{/if}
 										{/each}
-- 
cgit v1.2.3

